#include "generater.h"

void generater::generate_device_info(std::string & json_str_info)
{
    std::string time_1; 
    time_t t = time(NULL);
    char ch[64] = {0};
    char result[100] = {0};
    strftime(ch, sizeof(ch) - 1, "%Y-%m-%d %H:%M:%S", localtime(&t));
    sprintf(result, "%s", ch);
    time_1 = std::string(result);

    // Json::Value Heartbeat;

    // Json::Value info;
    // Json::Value node;
    // node["InfoType"] = "normal";
    // node["LocalPosition"] = "456787";
    // node["CurrentTime"] = time_1;
    // node["DetalSize"] = "9999";
    // node["FileName"] = "xxxxx.jpg";
    // node["Description"] = "  ";
    // info["DeviceInfo"] = node;

    Json::Value *info_node_ptr = new Json::Value;
    Json::Value *node_ptr = new Json::Value;

    (*node_ptr)["InfoType"] = "Normal";
    (*node_ptr)["LocalPosition"] = "456787";
    (*node_ptr)["CurrentTime"] = time_1;
    (*node_ptr)["DetailsSize"] = "655369";
    (*node_ptr)["FileName"] = "xxxxx.jpg";
    (*node_ptr)["Description"] = "  ";
    (*info_node_ptr)["DeviceInfo"] = *node_ptr;

    Json::FastWriter *fast_write_ptr = new Json::FastWriter;
    json_str_info = "*****"+fast_write_ptr ->write(*info_node_ptr)+"#####";
    delete info_node_ptr;
    delete node_ptr;
    delete fast_write_ptr;
}

void generater::generate_alarm(std::string & json_str_alarm)
{
    std::string time_1; 
    time_t t = time(NULL);
    char ch[64] = {0};
    char result[100] = {0};
    strftime(ch, sizeof(ch) - 1, "%Y-%m-%d %H:%M:%S", localtime(&t));
    sprintf(result, "%s", ch);
    time_1 = std::string(result);

    Json::Value *alarm_node_ptr = new Json::Value;
    Json::Value *node_ptr = new Json::Value;
    (*node_ptr)["AlarmType"] = "Crack";
    (*node_ptr)["StartPosition"] = "123455";
    (*node_ptr)["EndPosition"] = "123456";
    (*node_ptr)["AlarmLevel"] = "Marjor";
    (*node_ptr)["DetailsSize"] = "655369";
    (*node_ptr)["Filename"] = "xxxxxx.jpg";
    (*node_ptr)["Discription"] = "none";
    (*node_ptr)["CurrentTime"] = time_1;
    (*alarm_node_ptr)["AlarmInfomation"] = *node_ptr;
    

    Json::FastWriter *fast_write_ptr = new Json::FastWriter;
    json_str_alarm = "*****"+fast_write_ptr ->write(*alarm_node_ptr)+"#####";
    delete node_ptr;
    delete alarm_node_ptr;
    delete fast_write_ptr;
}

void generater::generate_helloack(std::string & json_str_helloack , std::string for_id)
{
    std::string time_1; 
    time_t t = time(NULL);
    char ch[64] = {0};
    char result[100] = {0};
    strftime(ch, sizeof(ch) - 1, "%Y-%m-%d %H:%M:%S", localtime(&t));
    sprintf(result, "%s", ch);
    time_1 = std::string(result);

    Json::Value *Heartbeat_ptr = new Json::Value;
    Json::Value *node_ptr = new Json::Value;

    (*node_ptr)["ID"] = for_id;
    (*node_ptr)["Type"] = "DetectStatus";
    (*node_ptr)["Line"] = "YangFan";
    (*node_ptr)["Station"] = "xingcheng-yancun";
    (*Heartbeat_ptr)["Hello"] = *node_ptr;

    Json::FastWriter *fast_write_ptr = new Json::FastWriter;
    json_str_helloack = "*****"+fast_write_ptr ->write(*Heartbeat_ptr)+"#####";

    delete node_ptr;
    delete Heartbeat_ptr;
    delete fast_write_ptr;
    //std::cout << "简单格式输出：\n" << heartbeat_str << std::endl;
}

void generater::generate_heartbeat(std::string & json_str_heartbeat , std::string for_id)
{
    std::string time_1; 
    time_t t = time(NULL);
    char ch[64] = {0};
    char result[100] = {0};
    strftime(ch, sizeof(ch) - 1, "%Y-%m-%d %H:%M:%S", localtime(&t));
    sprintf(result, "%s", ch);
    time_1 = std::string(result);

    Json::Value *Heartbeat_ptr = new Json::Value;
    Json::Value *node_ptr = new Json::Value;
    (*node_ptr)["ID"] = for_id;
    (*node_ptr)["Time"] = time_1;
    (*Heartbeat_ptr)["Heartbeat"] = *node_ptr;
    
    Json::FastWriter *fast_write_ptr = new Json::FastWriter;
    json_str_heartbeat = "*****"+fast_write_ptr ->write(*Heartbeat_ptr)+"#####";
    delete node_ptr;
    delete Heartbeat_ptr;
    delete fast_write_ptr;
    //std::cout << "简单格式输出：\n" << heartbeat << std::endl; 
}

std::string generater::generate_alarm_from_deque(const std::string &robotid,
                                                 const std::string &alarmtype,
                                                 const std::string &startposition,
                                                 const std::string &endposition,
                                                 const std::string &alarmlevel,
                                                 const std::string &detailsize,
                                                 const std::string &filename,
                                                 const std::string &description,
                                                 const std::string &currenttime)
{
    Json::Value *alarm_node_ptr = new Json::Value;
    Json::Value *node_ptr = new Json::Value;
    (*node_ptr)["RobotID"] = robotid;
    (*node_ptr)["AlarmType"] = alarmtype;
    (*node_ptr)["StartPosition"] = startposition;
    (*node_ptr)["EndPosition"] = endposition;
    (*node_ptr)["AlarmLevel"] = alarmlevel;
    (*node_ptr)["DetailsSize"] = detailsize;
    (*node_ptr)["Filename"] = filename;
    (*node_ptr)["Discription"] = description;
    (*node_ptr)["CurrentTime"] = currenttime;
    (*alarm_node_ptr)["AlarmInfomation"] = *node_ptr;

    std::string result;    

    Json::FastWriter *fast_write_ptr = new Json::FastWriter;
    result = "*****"+fast_write_ptr ->write(*alarm_node_ptr)+"#####";
    delete node_ptr;
    delete alarm_node_ptr;
    delete fast_write_ptr;
    return result;
}


std::string generater::generate_info_from_deque(const std::string &robotid,
                                                const std::string &infotype,
                                                const std::string &localposition,
                                                const std::string &currenttime,
                                                const std::string &detailssize,
                                                const std::string &filename,
                                                const std::string &description)
{
    Json::Value *info_node_ptr = new Json::Value;
    Json::Value *node_ptr = new Json::Value;
    (*node_ptr)["RobotID"] = robotid;
    (*node_ptr)["InfoType"] = infotype;
    (*node_ptr)["LocalPosition"] = localposition;
    (*node_ptr)["CurrentTime"] = currenttime;
    (*node_ptr)["DetailsSize"] = detailssize;
    (*node_ptr)["FileName"] = filename;
    (*node_ptr)["Description"] = description;
    (*info_node_ptr)["DeviceInfo"] = *node_ptr;

    std::string result; 

    Json::FastWriter *fast_write_ptr = new Json::FastWriter;
    result = "*****"+fast_write_ptr ->write(*info_node_ptr)+"#####";
    delete info_node_ptr;
    delete node_ptr;
    delete fast_write_ptr;
    return result;
}


generater::generater()
{

}
generater::~generater()
{

}
